package com.yihubang.taobaokotlin.ui.adapter

import android.content.Context
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yihubang.taobaokotlin.R
import com.yihubang.taobaokotlin.model.HomePagerContent
import com.yihubang.taobaokotlin.utils.UrlUtils

/*
 * class title: 
 * Author by RenChunLin, Email 18957806320@163.com, Date on 2021/5/11.
 * PS: Not easy to write code, please indicate.
 */
class LinearItemContentAdapter(layoutResId: Int, data: MutableList<HomePagerContent.DataBean>,context: Context) :
    BaseQuickAdapter<HomePagerContent.DataBean, BaseViewHolder>(layoutResId, data) {

    private var datas= mutableListOf<HomePagerContent.DataBean>()
    private var aContext: Context? = null

    init {
        aContext=context
        datas=data
    }

    override fun convert(helper: BaseViewHolder, item: HomePagerContent.DataBean) {
        helper.setText(R.id.goods_title, item.title)
        val pictUrl = item.pict_url
        val coverPath = UrlUtils.getCoverPath(pictUrl)
        Glide.with(aContext!!).load(coverPath).into((helper.getView<View>(R.id.goods_cover) as ImageView))
    }

    fun addListData(data: MutableList<HomePagerContent.DataBean>){
        val size = datas.size
        datas.addAll(size,data)
        notifyItemRangeChanged(size,data.size)
    }
}